<?php
include('connect_db.php');
/*if logged in, redirect to homepage */
if (!checkLoggedin())
{
	//header('Location: login.php');
	header('Location: login.php');
}

$err = ' ';
if(isset($_POST) && isset($_POST['amount']))/*check if the user select a house*/
{
	$err = 'Please select a house.';
}
?>

<script>
	function Refresh(id)
	{
		location.href="addbill.php?house_id=" + id;
	}
</script>

<?php include('templates/main/header.php'); ?>
    <div id="body">
		<div id="content" class="right_sidebar">
		<div id="addbill">
		<hr>

		<?php if ($err != ' ') { ?>
		<div class="errors">
			<p><?php echo $err; ?></p>
		</div>
		<?php } ?>
		<div class="errors clear"></div>

		<h1>Please 
			<select id="houses-form" class="form2" name="houses" onChange="Refresh(this.value)">
				<option value="0">Select a House</option>
				<?php
					$query = "SELECT * FROM houses
								JOIN houses_users ON houses.id = houses_users.house_id
								WHERE houses_users.user_id = " . $_SESSION['id'];
					$results = mysql_query($query);
					while($row = mysql_fetch_array($results))
					{
						echo '<option value="'.$row['house_id']."\">".$row['name'].'</option>';
					}
				?>
			</select>
		</h1>
		<hr>
		<br />
		<br />
		
		<form action="addbill_house.php" method="post" accept-charset="utf-8">
		<h2>House Members</h2>
		
		<label>
			Amount($)*:
			<input name="amount" value="" type="text">
		</label>

		<label>
			Reason:
			<textarea name="notes" cols="90" rows="7" value="" ></textarea>
		</label>

		<label>
			<div class="sameline">Category:</div>
			<select name="category_id">
			<option value="1">Rent</option>
			<option value="2">Electricity</option>
			<option value="3">Water</option>
			<option value="4">Gas</option>
			<option value="5">Cable</option>
			<option value="6">Food supplies</option>
			<option value="7">House supplies</option>
			<option value="8">Entertainment</option>
			<option value="9">Equipments</option>
			<option value="10">Repair</option>
			</select>
		</label>
		
		
		<input name="" value="Add" type="submit">
		</form>
	</div>





	</div>
	</div>

<?php include('templates/main/footer.php'); ?>